﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Users/Index.cshtml";
}
<script src="~/Scripts/jquery-1.8.2.min.js"></script>
<script src="~/Scripts/layer/layer.js"></script>
<link href="~/css/bootstrap.min.css" rel="stylesheet" />

<script src="~/js/bootstrap.min.js"></script>
<h2>千百亿花卉商城</h2>
<form>
    花卉分类：<select id="Select1" name="FlowersGiftsType">
        <option value="送女友">送女友</option>
        <option value="送亲人">送亲人</option>
        <option value="送父母">送父母</option>
    </select>
    <select id="Select1" name="FlowersStockType">
        <option value="有货">有货</option>
        <option value="无货不接受预定">无货不接受预定</option>
        <option value="无货但接受预定">无货但接受预定</option>
    </select>
    <input id="Submit1" type="submit" value="搜索" />
</form>
    <hr />
    <table >
        <tr>
            @{
                for (var i = 1; i <= ViewBag.lis.Count; i++)
                {
                    if (i % 5 == 1)
                    {
                        @Html.Raw("<tr>");
                    }
                    <td style="width:200px;height:200px;">
                        <dl>
                            <dd style="text-align:center"><img src="@ViewBag.lis[i-1].FlowersImg" alt="" style="width:100px;height:100px;" /></dd>
                            
                            <dt style="text-align:center">
                                @ViewBag.lis[i - 1].FlowersName
                            </dt>
                            <dt style="text-align:center">
                                ￥@ViewBag.lis[i - 1].Sales_unit_price 元/束
                            </dt>
                            <dt style="text-align:center">@ViewBag.lis[i - 1].FlowersAddTime</dt>
                            <dt style="text-align:center">
                                
                                @if (ViewBag.lis[i - 1].FlowersStock == 0 && ViewBag.lis[i - 1].FlowersStockType == "无货但接受预定")
                                {
                                    <input id="Button1" class="btn btn-sm btn-primary" type="button" value="预定" />
                                }
                                else
                                {
                                    <input id="Button1" class="btn btn-sm btn-primary" type="button" value="购买" onclick="by(this,@ViewBag.lis[i-1].FlowersID,'@ViewBag.lis[i - 1].FlowersName','@ViewBag.lis[i - 1].Sales_unit_price','@ViewBag.lis[i-1].FlowersImg')" />
                                }
                            </dt>
                    </dl></td>
                    if (i % 5 == 0 || i == ViewBag.lis.Count)
                    {
                        @Html.Raw("</tr>");
                    }
                }
            }
        </tr>
    </table>


<script>
    function by(bjj,id,name,price,url)
    {

        
        var html = "<table id='tb' class='table table-hover'>";
        html += "<tr><td>名称</td><td><hidden id='n'>" + name + "</hidden></td></tr>";
        html += "<tr><td>单价</td><td><hidden id='p' >" + price + "</hidden></td></tr>";
        html += "<tr><td></td><td><img src='"+url+"' id='img' style='width:30px;height:30px;' /></td></tr>";
        html+="<tr><td>数量</td><td><input id='Text1' type='text' name='sums'/></td></tr>";
        html += "<tr><td ><input id='Submit1' type='button' class='btn btn-default'  value='保存'onclick='bao(" + id + ")' /></td><td><td></tr></table>";
        layer.open({
            type: "1",
            area: ["300px", "300px"],
            title: "订单信息",
            content:html
        })
    }
    //添加到购物车
    function bao(obj)
    {
        
        var name = $("#n").text();
        var price = $("#p").text();
        var url = $("#img").attr("src");
       var id = obj;
       var sums = $("#Text1").val();
       //alert(sums);
       $.ajax({
           url: "/FlowersStrock/AddshopCar",
            data: { commodityID: id, purchaseNumber: sums ,FlowersName:name,Sales_unit_Price:price,FlowerUrl:url},
            dataType: "json",
            type: "post",
            success:function(bbj){
                //alert(bbj);
                if(bbj>0)
                {
                    alert("添加成功");
                    layer.closeAll();
                }
                else
                {
                    if(bbj==-1)
                    {
                        alert('请先登录');
                    }
                    alert('添加失败！');

                }
            }
       })
       
    }
</script>
